﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;
using Gift.DAL;
using Gift.Model;

using System.Text;

namespace WebSite.cn
{
    public partial class order : BasePage
    {
        // Fields
        public string address1 = "";
        public string payDescription = "";
        public string cardprice = "0";
        public string carmsg = "";
        public string cname = "";
        public string cname1 = "";
        public string content = "";
        public string email = "";
        public string email1 = "";
        public string ocard = "";
        public string ocode = "";
        public string content1 = "";
        public string omsg = "";
        public string omsg1 = "";
        public string opay = "";
        public string orderscore = "0";
        public string oscore = "";
        public string oship = "";
        public string otime = "";
     //   public string payprice = "0";
        public string phone = "";
        public string phone1 = "";
        public string post1 = "";
        public string scoremsg = "未使用积分";
      //  public string scoreprice = "0";
     //   public string shiprice = "0";
        public string sumprice = "0";
        public string tel = "";
        public string tel1 = "";
        public string totalprice = "0";
        public string ordercode = "";
        //static bool bProcessOrderProfession = false;
        //static bool bProcessOrderMember = false;
        //static bool bProcessOrderOther = false;

        public string sendDate = "";

        readonly OrderAccount theOrderAccount = new OrderAccount();
        readonly MemberAccount theMemberAccount = new MemberAccount();
        readonly Member theMember = new Member();

        decimal _payMoneyByCard = 0;
        decimal _payMoneyByOther = 0;


        private decimal PayMoneyByCard
        {
            get {
                if (_payMoneyByCard > 0)
                {
                    return _payMoneyByCard;
                }
                else
                {
                    if (!string.IsNullOrEmpty(base.Request.Form["cardpaymoney"]))
                    {
                        _payMoneyByCard = decimal.Parse(base.Request.Form["cardpaymoney"]);
                        return _payMoneyByCard;
                    }
                    else
                    {
                        return 0;
                    }
                }
            }
            set {
                _payMoneyByCard = value;
            }
        }

        private decimal PayMoneyByOther
        {
            get {
                if (_payMoneyByOther > 0)
                {
                    return _payMoneyByOther;
                }
                else
                {
                    if (!string.IsNullOrEmpty(base.Request.Form["paymoney"]))
                    {
                        _payMoneyByOther = decimal.Parse(base.Request.Form["paymoney"].ToString());
                        return _payMoneyByOther;
                    }
                    else
                    {
                        return 0;
                    }
                }

            }
            set
            {
                _payMoneyByOther = value;
            }
        }

      
        void InitReseiveClient()
        {
            if (Request.Form["chk1"] == "1")
            {
                cname1 = Request.Form["cname"];
                email1 = Request.Form["email"];
                omsg1 = Request.Form["omsg"];
                phone1 = Request.Form["phone"];
                content1 = Request.Form["content"];
                post1 = Request.Form["post"];
                tel1 = Request.Form["tel"];
                address1 = Request.Form["ddlProvence"] + Request.Form["ddlArea"] + Request.Form["address"];
            }
            else
            {
                cname1 = Request.Form["cname1"];
                email1 = Request.Form["email1"];
                omsg1 = Request.Form["omsg1"];
                phone1 = Request.Form["phone1"];
                content1 = Request.Form["content1"];
                post1 = Request.Form["post1"];
                tel1 = Request.Form["tel1"];
                address1 =  Request.Form["address1"];
            }
            sendDate = Request.Form["senddate"];
            if (string.IsNullOrEmpty(sendDate))
            {
                sendDate = DateTime.Now.AddDays(3).ToString("yyyy-MM-dd");
            }

            if(string.IsNullOrEmpty(cname1))
            {
                   base.Response.Write("<script language=javascript>window.location.href='index.aspx';</script>");
                    base.Response.End();
            }
        }

        // Methods
        private void PayByCardInProfessionArea()
        {
            //if (bProcessOrderProfession == true)
            //{
            //    this.PayByCardInProfessionArea();
            //}
            //bProcessOrderProfession = true;
                string str6;
                if (base.Request.Form["totalprice"] == null)
                {
                    base.Response.Write("<script language=javascript>window.location.href='index.aspx';</script>");
                    base.Response.End();
                }
             
                this.InitReseiveClient();
                string strMaxOrderID = Request.Form["ordercode"];
                string strOrderCode = Request.Form["ordercode"]; // DateTime.Now.ToShortDateString().Replace("-", "") + str4;
                if (UserMemberId != null)
                {
                    str6 = UserMemberId;
                }
                else
                {
                    str6 = "0";
                }
                this.sumprice = base.Request.Form["totalprice"];

             
                string sCardCodes = "";

                decimal dTotalCardPrice = 0;
                for (int i = 0; i < UserCardCodeList.Count; i++)
                {
                    dTotalCardPrice += decimal.Parse(UserCardCodeList[i].UserCardPrice);
                    sCardCodes += "'" + UserCardCodeList[i].UserCardCode + "',";
                }
                if (sCardCodes.Length > 0) sCardCodes = sCardCodes.Substring(0, sCardCodes.Length - 1);
                this.cardprice = dTotalCardPrice.ToString();

                if (decimal.Parse(this.sumprice) != dTotalCardPrice)
                {
                    UserCardCodeList = null;
                    base.Response.Write("<script language=javascript>alert('购买失败!');window.location.href='index.aspx';</script>");
                    base.Response.End();
                }

                string sPay = string.Empty;

                    sPay = "15";

                string sUpdateCard = string.Empty;
                string cardid = string.Empty;
                string totalscore = string.Empty;
                string ship = string.Empty;
                if(UserCardCodeList == null)
                {
                   cardid =  base.Request.Form["cardid"];
                   totalscore = base.Request.Form["totalscore"];
                   ship = "-1";
                }else
                {
                    foreach (UserCard inCard in UserCardCodeList)
                    {
                        dbCard tmpCard = new Card().GetModel(inCard.UserCardCode, inCard.UserCardPassword);
                        if (tmpCard == null || tmpCard.states != 1)
                        {
                            UserCardCodeList = null;
                            base.Response.Write("<script language=javascript>alert('购买失败!');window.location.href='index.aspx';</script>");
                            base.Response.End();
                        }
                    }
                    cardid = "0";
                    totalscore = "0";
                    ship = "-1";
                    this.tdTotal.Visible = false;
                    this.tdTotalPrice.Visible = false;

                    sUpdateCard = "update DB_Card set states = 2,closeTime = getdate() where cardcode in (" + sCardCodes + ");";


                    StringBuilder strInsertOrderAccount = new StringBuilder();

                    for(int m=0;m<UserCardCodeList.Count; m++)
                    {
                        strInsertOrderAccount.Append(" insert tbOrderAccount(OrderCode,CardId,CardAdded,AddDate) values('" + strOrderCode +"',"
                                                      + UserCardCodeList[m].UserCardId.ToString() + ","
                                                      + "1,"
                                                      + "getdate());");
                    }

                    sUpdateCard = sUpdateCard + strInsertOrderAccount.ToString();
                }    
               
                this.totalprice = Convert.ToString((float)(((Convert.ToSingle(this.sumprice))  - Convert.ToSingle(this.cardprice))));
                SQLAccess.DoSql(string.Concat(new object[] { 
                "insert into DB_Order (orderid,ordercode,memberid,pay,ship,states,cname,tel,phone,post,address,email,content,cname1,tel1,phone1,post1,address1,email1,ordertime,sendDate,languages,totalprice,cardprice,scoreprice,cardid,orderscore) values (", strMaxOrderID, ",'", strOrderCode, "',", str6, ",'", sPay, "',", ship, ",0,'", base.Request.Form["cname"], "','", base.Request.Form["tel"], "','", base.Request.Form["phone"], 
                "','", base.Request.Form["post"], "','", base.Request.Form["address"], "','", base.Request.Form["email"], "','", base.Request.Form["content"], "','", cname1, "','", tel1, "','", phone1, "','", post1, 
                "','", address1, "','", email1, "','", DateTime.Now, "','" + sendDate + "',1,'", this.totalprice, "',", this.cardprice, ",", 0, ",", cardid, ",", totalscore, 
                ")",sUpdateCard,";"
             }));
                SQLAccess.DoSql(" update DB_Shoppro set proku1 = isnull(proku1,0) - db_Car.pronum "
                                + " from DB_Shoppro,db_Car "
                                + " where DB_Shoppro.proid = db_Car.productid  and db_Car.carid in(" + base.Request.Form["carid"] + ") ;"
                                 + " update DB_Car set flag=1,orderid=" + strMaxOrderID + " where carid in(" + base.Request.Form["carid"] + ")");

                Response.Write("<script>('购买成功！')</script>");
                UserCardCodeList = null;
               // bProcessOrderProfession = false;
                base.Response.Write("<script language=javascript>window.location.href='order.aspx?oid=" + strMaxOrderID + "';</script>");
                base.Response.End();

          }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                  string str = base.Request.Form["action"];
               if (str == "add")
              {
                  if (Request.Form["TempType"] == "1")
                    {
                        if (UserCardCodeList != null)
                        {
                            this.PayByCardInProfessionArea();
                        }
                        else
                        {
                            base.Response.Write("<script language=javascript>alert('购买失败！操作时间过期，请重新登录购买！');window.location.href='ProfessionArea.aspx?sid=2';</script>");
                            base.Response.End();
                        }
                    }
                  else if (Request.Form["TempType"] == "2")
                    {
                        if (UserMemberId != null)
                        {
                            this.PayByMemberCard();
                        }
                        else
                        {
                            base.Response.Write("<script language=javascript>alert('购买失败！操作时间过期，请重新登录购买！');window.location.href='hotpro.aspx?sid=4';</script>");
                            base.Response.End();
                        }
                    }
                    else
                    {
                        this.PayByOther();
                    }
                }
                else if (base.Request.QueryString["oid"] != null)
                {
                    this.BindForm();
                }
                else
                {
                    base.Response.Write("<script language=javascript>window.location.href='index.aspx';</script>");
                    base.Response.End();
                }

            }
          }

        private void PayByOther()
        {
            //if (bProcessOrderOther == true)
            //{
            //    this.PayByOther();
            //}
            //bProcessOrderOther = true;
            string sMemberId = "0";
            if (UserMemberId != null) sMemberId = UserMemberId;
                if (base.Request.Form["totalprice"] == null)
                {
                    base.Response.Write("<script language=javascript>window.location.href='index.aspx';</script>");
                    base.Response.End();
                }
                this.InitReseiveClient();
                string sOrderIdentity = re.maxid("", "DB_Order", "orderid");
                string sOrderCode = Request.Form["ordercode"];

                this.sumprice = base.Request.Form["totalprice"];

                this.cardprice = PayMoneyByCard.ToString();

                string sPay = "6";
                       

                string updateCard = string.Empty;
                string cardid = string.Empty;
                string totalscore = string.Empty;
                string ship = string.Empty;

                    totalscore = "0";
                    cardid = "0";
                    ship = "0";
                    this.tdTotal.Visible = false;
                    this.tdTotalPrice.Visible = false;      
               
                this.totalprice = Convert.ToString((decimal.Parse(this.sumprice))  - decimal.Parse(this.cardprice));
                SQLAccess.DoSql(string.Concat(new object[] { 
                "insert into DB_Order (orderid,ordercode,memberid,pay,ship,states,cname,tel,phone,post,address,email,content,cname1,tel1,phone1,post1,address1,email1,ordertime,sendDate,languages,totalprice,cardprice,scoreprice,cardid,orderscore) values (", sOrderIdentity, ",'", sOrderCode, "',", sMemberId, ",'", sPay, "',", ship, ",0,'", base.Request.Form["cname"], "','", base.Request.Form["tel"], "','", base.Request.Form["phone"], 
                "','", base.Request.Form["post"], "','", base.Request.Form["address"], "','", base.Request.Form["email"], "','", base.Request.Form["content"], "','", cname1, "','", tel1, "','", phone1, "','", post1, 
                "','", address1, "','", email1, "','", DateTime.Now, "','" + sendDate + "' ,1,'", this.totalprice, "',", this.cardprice, ",", 0, ",", cardid, ",", totalscore, 
                ")",updateCard,";"
             }));

                           SQLAccess.DoSql(" update DB_Shoppro set proku1 = isnull(proku1,0) - db_Car.pronum "
                                + " from DB_Shoppro,db_Car "
                                + " where DB_Shoppro.proid = db_Car.productid   and db_Car.carid in(" + base.Request.Form["carid"] + ") ;"
                                + " update DB_Car set flag=1,orderid=" + sOrderIdentity + " where carid in(" + base.Request.Form["carid"] + ")");

                Response.Write("<script>('购买成功！')</script>");
                UserCardCodeList = null;
              //  bProcessOrderOther = false;
                base.Response.Write("<script language=javascript>window.location.href='order.aspx?oid=" + sOrderIdentity + "';</script>");
                base.Response.End();

          
        }

        private void PayByMemberCard()
        {
            //if (bProcessOrderMember == true)
            //{
            //    this.PayByMemberCard();
            //}
            //bProcessOrderMember = true;
            string sMemberId = "0";
            if (UserMemberId != null) sMemberId = UserMemberId;
            if (base.Request.Form["totalprice"] == null)
            {
                base.Response.Write("<script language=javascript>window.location.href='index.aspx';</script>");
                base.Response.End();
            }
            this.InitReseiveClient();
            string sOrderIdentity = Request.Form["ordercode"];
            string sOrderCode = Request.Form["ordercode"];

            if (decimal.Parse(base.Request.Form["totalprice"]) < 100)
            {
                this.sumprice = (decimal.Parse(base.Request.Form["totalprice"]) + 10).ToString();
            }
            else
            {
                this.sumprice = (decimal.Parse(base.Request.Form["totalprice"])).ToString();
            }

          
            this.cardprice = sumprice;
            string sPay = "15";

            int iResult = theMemberAccount.UserSpendMoney(int.Parse(sMemberId), decimal.Parse(sumprice), sOrderCode);
                if (iResult < 0)
                {
                    base.Response.Write("<script>alert('余额不足，购买失败！')</script>");
                    base.Response.Write("<script language=javascript>window.location.href='account.aspx';</script>");
                    base.Response.End();
                }

           
            string updateCard = string.Empty;
            string cardid = string.Empty;
            string totalscore = string.Empty;
            string ship = string.Empty;

            totalscore = "0";
            cardid = "0";
            ship = "0";
            this.tdTotal.Visible = false;
            this.tdTotalPrice.Visible = false;

            this.totalprice = Convert.ToString((decimal.Parse(this.sumprice)) - decimal.Parse(this.cardprice));

            int iCheckCodeResult = theMemberAccount.CheckOrderCode(sOrderCode);
            if (iCheckCodeResult > 0)
            {
                base.Response.Write("<script>alert('订单成功！')</script>");
                base.Response.Write("<script language=javascript>window.location.href='order.aspx?oid=" + sOrderIdentity + "';</script>");
                base.Response.End();
            }

            StringBuilder sbSQL = new StringBuilder();
            sbSQL.Append(string.Concat(new object[] { 
                "insert into DB_Order (orderid,ordercode,memberid,pay,ship,states,cname,tel,phone,post,address,email,content,cname1,tel1,phone1,post1,address1,email1,ordertime,sendDate,languages,totalprice,cardprice,scoreprice,cardid,orderscore) values (", sOrderIdentity, ",'", sOrderCode, "',", sMemberId, ",'", sPay, "',", ship, ",0,'", base.Request.Form["cname"], "','", base.Request.Form["tel"], "','", base.Request.Form["phone"], 
                "','", base.Request.Form["post"], "','", base.Request.Form["address"], "','", base.Request.Form["email"], "','", base.Request.Form["content"], "','", cname1, "','", tel1, "','", phone1, "','", post1, 
                "','", address1, "','", email1, "','", DateTime.Now, "','" + sendDate + "' ,1,'", this.totalprice, "',", this.cardprice, ",", 0, ",", cardid, ",", totalscore, 
                ")",updateCard,";"
             }));
            sbSQL.Append(" update DB_Shoppro set proku1 = isnull(proku1,0) - db_Car.pronum "
                                + " from DB_Shoppro,db_Car "
                                + " where DB_Shoppro.proid = db_Car.productid   and db_Car.carid in(" + base.Request.Form["carid"] + ") ;"
                                 + " update DB_Car set flag=1,orderid=" + sOrderIdentity + " where carid in(" + base.Request.Form["carid"] + ");");

            theMemberAccount.UserSpendMoneyForOrder(int.Parse(sMemberId), decimal.Parse(sumprice), sOrderCode,sbSQL.ToString());

            Response.Write("<script>('购买成功！')</script>");
            UserCardCodeList = null;
            //bProcessOrderMember = false;
            base.Response.Write("<script language=javascript>window.location.href='order.aspx?oid=" + sOrderIdentity + "';</script>");
            base.Response.End();

        }

      

        private void BindForm()
        {
                DataTable table;
             DataTable table2;
             table = SQLAccess.GreatDs("select orderid,ordercode,pay,ship,cname,tel,phone,post,address,email,content,cardprice,scoreprice,cname1,cardid,orderscore,tel1,phone1,post1,address1,email1,content1,ordertime,sendDate from DB_Order where orderid=" + base.Request.QueryString["oid"] + "").Tables[0];
                if (table.Rows.Count > 0)
                {
                    this.ocode = table.Rows[0]["ordercode"].ToString();
                    this.otime = table.Rows[0]["ordertime"].ToString();
                    this.cardprice = table.Rows[0]["cardprice"].ToString();
                    this.orderscore = table.Rows[0]["orderscore"].ToString();
                    this.omsg = "姓 名 : " + table.Rows[0]["cname"].ToString() + "<br />联系电话 : " + table.Rows[0]["tel"].ToString() + "<br />手 机 :" + table.Rows[0]["phone"].ToString() + "<br /> ";
                    this.omsg1 = "姓 名 : " + table.Rows[0]["cname1"].ToString() + "<br />收货地址 : " + table.Rows[0]["address1"].ToString() + "<br />联系电话 : " + table.Rows[0]["tel1"].ToString() + "<br />手 机 : " + table.Rows[0]["phone1"].ToString() + "<br />送货时间 :" + table.Rows[0]["senddate"].ToString() + "<br />";
                    this.content1 = table.Rows[0]["content1"].ToString();
                    table2 = SQLAccess.GreatDs("select payname,pay,paycontent from DB_Pay where payid in (" + table.Rows[0]["pay"].ToString() + ")").Tables[0];
                    this.opay = "<ul>";
                    if (table2.Rows.Count > 0)
                    {
                        this.opay = this.opay + "<li>" + table2.Rows[0][0].ToString() + "<br/>" + table2.Rows[0][2].ToString() + "</li>";
                    }
                    this.opay = this.opay + "</ul>";
                    table2 = SQLAccess.GreatDs("select shippingname,shippingcontent,shippingpay from DB_Shipping where shippingid=" + table.Rows[0]["ship"].ToString() + "").Tables[0];
                    if (table2.Rows.Count > 0)
                    {
                        this.oship = table2.Rows[0][0].ToString();
                        //  this.shiprice = table2.Rows[0][2].ToString();
                    }
                    table2 = SQLAccess.GreatDs("select DB_Car.carid,DB_Car.pronum,DB_Car.price,DB_Car.sumprice,DB_Car.contents,DB_Shoppro.typeid,DB_Shoppro.proname,DB_Shoppro.proprice1,DB_Shoppro.propic2,DB_Shoppro.proid  from DB_Car inner join DB_Shoppro on DB_Car.productid=DB_Shoppro.proid where DB_Car.flag=1 and DB_Car.orderid=" + table.Rows[0]["orderid"].ToString() + "").Tables[0];
                    if (table2.Rows.Count > 0)
                    {
                        foreach (DataRow row in table2.Rows)
                        {
                            this.sumprice = string.Format("{0:f}", Convert.ToSingle(this.sumprice) + Convert.ToSingle(row["sumprice"]));
                            this.carmsg = this.carmsg + "<tr>";
                            string carmsg = this.carmsg;
                            this.carmsg = carmsg + "<td bgcolor='#FFFFFF'><a href='products_details.aspx?tid=" + row["typeid"].ToString() + "&pid=" + row["proid"].ToString() + "' target=_blank><img src='../uploadfile/product/" + row["propic2"].ToString() + "' align='left' border='0' width='106px' /></a></td>";
                            string str11 = this.carmsg;
                            this.carmsg = str11 + "<td bgcolor='#FFFFFF'><a href='products_details.aspx?tid=" + row["typeid"].ToString() + "&pid=" + row["proid"].ToString() + "' class='blue' target=_blank>" + row["proname"].ToString() + "</a><br /><br/>" + row["contents"].ToString() + "</td>";
                            this.carmsg = this.carmsg + "<td bgcolor='#FFFFFF'>" + string.Format("{0:f}", row["price"]) + "元</td>";
                            this.carmsg = this.carmsg + "<td bgcolor='#FFFFFF'>" + row["pronum"].ToString() + "</td>";
                            this.carmsg = this.carmsg + "<td bgcolor='#FFFFFF'>" + string.Format("{0:f}", row["sumprice"]) + " 元</td>";
                            this.carmsg = this.carmsg + "</tr>";
                        }
                    }

                    this.totalprice = string.Format("{0:f}", (decimal.Parse(this.sumprice) - decimal.Parse(this.cardprice)));
                    if (UserCardCodeList != null)
                    {
                        decimal dTotalPrice = 0;
                        string sCardCodes = "";
                        for (int i = 0; i < UserCardCodeList.Count; i++)
                        {
                            dTotalPrice += decimal.Parse(UserCardCodeList[i].UserCardPrice);
                            sCardCodes += UserCardCodeList[i].UserCardCode + ",";
                        }
                        sCardCodes = sCardCodes.Substring(0, sCardCodes.Length - 1);
                        this.payDescription = "礼品卡卡号：" + sCardCodes + " 支付金额：" +  dTotalPrice.ToString();
                        this.cardprice = dTotalPrice.ToString();
                    }
                    else
                    {
                        this.payDescription = " 账户支付金额：" + string.Format("{0:f}", this.cardprice) + "<br/>";

                                        //    + " 您还需支付剩余费用:" + string.Format("{0:f}", this.totalprice);
                    }
            }       
         }
    }
}




        //// Methods
        //private void PayByCardInProfessionArea()
        //{    
        //        string str6;
        //        if (base.Request.Form["totalprice"] == null)
        //        {
        //            base.Response.Write("<script language=javascript>window.location.href='index.aspx';</script>");
        //            base.Response.End();
        //        }
        //        string str4 = re.maxid("", "DB_Order", "orderid");
        //        string str5 = theOrderAccount.GenerateOrderCode(); // DateTime.Now.ToShortDateString().Replace("-", "") + str4;
        //        if (this.Session["memberid"] != null)
        //        {
        //            str6 = this.Session["memberid"].ToString();
        //        }
        //        else
        //        {
        //            str6 = "0";
        //        }
        //        this.sumprice = base.Request.Form["totalprice"];

        //            this.cardprice = UserCardPrice;

        //        //if (!string.IsNullOrEmpty(base.Request.Form["scoreprice"] ))
        //        //{
        //        //    this.scoreprice = base.Request.Form["scoreprice"];
        //        //}
        //        //else
        //        //{
        //        //    this.scoreprice = "0";
        //        //}
        //        string sPay = string.Empty;

        //            sPay = "15";

        //        //table2 = SQLAccess.GreatDs("select pay from DB_Pay where payid=" + sPay + "").Tables[0];
        //        //if (table2.Rows.Count > 0)
        //        //{
        //        //    this.payprice = table2.Rows[0][0].ToString();
        //        //}
        //        //if (UserCardCode == null)
        //        //{
        //        //    table2 = SQLAccess.GreatDs("select shippingpay from DB_Shipping where shippingid=" + base.Request.Form["ship"] + "").Tables[0];
        //        //    if (table2.Rows.Count > 0)
        //        //    {
        //        //        this.shiprice = table2.Rows[0][0].ToString();
        //        //    }
        //        //}

        //        string updateCard = string.Empty;
        //        string cardid = string.Empty;
        //        string totalscore = string.Empty;
        //        string ship = string.Empty;
        //        if(UserCardCode == null)
        //        {
        //           cardid =  base.Request.Form["cardid"];
        //           totalscore = base.Request.Form["totalscore"];
        //           ship = "-1";
        //        }else
        //        {
        //            cardid = new Card().GetModel(UserCardCode, UserCardPassword).cardid.ToString();
        //            totalscore = "0";
        //            ship = "-1";
        //            this.tdTotal.Visible = false;
        //            this.tdTotalPrice.Visible = false;
        //            updateCard = "update DB_Card set states = 2,closeTime = getdate() where cardcode = " + UserCardCode;
        //        }


               
               
        //        this.totalprice = Convert.ToString((float)(((Convert.ToSingle(this.sumprice))  - Convert.ToSingle(this.cardprice))));
        //        SQLAccess.DoSql(string.Concat(new object[] { 
        //        "insert into DB_Order (orderid,ordercode,memberid,pay,ship,states,cname,tel,phone,post,address,email,content,cname1,tel1,phone1,post1,address1,email1,ordertime,languages,totalprice,cardprice,scoreprice,cardid,orderscore) values (", str4, ",'", str5, "',", str6, ",", sPay, ",", ship, ",0,'", base.Request.Form["cname"], "','", base.Request.Form["tel"], "','", base.Request.Form["phone"], 
        //        "','", base.Request.Form["post"], "','", base.Request.Form["address"], "','", base.Request.Form["email"], "','", base.Request.Form["content"], "','", base.Request.Form["cname1"], "','", base.Request.Form["tel1"], "','", base.Request.Form["phone1"], "','", base.Request.Form["post1"], 
        //        "','", base.Request.Form["address1"], "','", base.Request.Form["email1"], "','", DateTime.Now, "',1,'", this.totalprice, "',", this.cardprice, ",", 0, ",", cardid, ",", totalscore, 
        //        ")",updateCard,";"
        //     }));
        //        SQLAccess.DoSql("update DB_Car set flag=1,orderid=" + str4 + " where carid in(" + base.Request.Form["carid"] + ")");
        //       // if (this.Session["memberid"] != null)
        //       // {
        //           // SQLAccess.DoSql(string.Concat(new object[] { "update DB_Card set states=1 where cardid=", base.Request.Form["cardid"], "" }));
        //            //if (this.scoreprice != "0")
        //            //{
        //            //    table = SQLAccess.GreatDs("select score1,score2,score3 from DB_Member where memberid=" + this.Session["memberid"] + "").Tables[0];
        //            //    if (table.Rows.Count > 0)
        //            //    {
        //            //        SQLAccess.DoSql(string.Concat(new object[] { "update DB_Member set score2=", Convert.ToSingle(table.Rows[0]["score2"]) + Convert.ToSingle(base.Request.Form["scoreprice"]), ",score3=", Convert.ToSingle(table.Rows[0]["score3"]) - Convert.ToSingle(base.Request.Form["scoreprice"]), " where memberid=", this.Session["memberid"], "" }));
        //            //        SQLAccess.DoSql(string.Concat(new object[] { "insert into DB_Score (memberid,scorename,scoreprice,content,updatetime,scoretype) values (", this.Session["memberid"], ",'定单号：", str5, "','-", base.Request.Form["scoreprice"], "','下单使用积分：", base.Request.Form["scoreprice"], "','", DateTime.Now, "',1)" }));
        //            //    }
        //            //}
        //       // }
        //        Response.Write("<script>('购买成功！')</script>");
        //        UserCardCode = null;
        //        UserCardPassword = null;
        //        UserCardPrice = null;
        //        base.Response.Write("<script language=javascript>window.location.href='order.aspx?oid=" + str4 + "';</script>");
        //        base.Response.End();

        //  }